﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PFWFA
{
    public partial class BMIcalc : Form
    {
        public BMIcalc()
        {
            InitializeComponent();
        }

        private void btnCalculate_Click(object sender, EventArgs e)
        {
            double height;
            double weight;

            try
            {
                weight = Convert.ToDouble(boxWeight.Text);
                height = Convert.ToDouble(boxHeight.Text);
            }
            catch(System.FormatException ex)
            {
                weight = 1;
                height = 1;
                boxHeight.Text = "1";
                boxWeight.Text = "1";
            }

            double result = weight / (height * height);
            if(rbEnglish.Checked == true)
            {
                result *= 703;
            }

            result = Math.Round(result, 2);
            lblResult.Text = Convert.ToString(result);
        }

        private void btnBMIclose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void rbMetric_Click(object sender, EventArgs e)
        {
            lblWeightUnits.Text = "kilograms";
            lblHeightUnits.Text = "meters";
        }

        private void rbEnglish_Click(object sender, EventArgs e)
        {
            lblWeightUnits.Text = "pounds";
            lblHeightUnits.Text = "inches";
        }

                
    }
}
